/**
 * * @author Eric Jahn * Course: Object Oriented Programming * Final Project *
 * Due Date: August 3, 2012
 */
package oop.chat.data;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import oop.chat.user.Contact;
import oop.chat.user.UserAccount;

/**
 * this class represents a single message from an user
 * @author Eric Jahn
 */
public class Message implements Serializable
{
    //the message itself
	private String message;
    //timestamp of the message          
    private Timestamp timestamp;
    //destination and source of the address          
    private UserAccount source;
    private Contact destination;

    /**
     * * default constructor
     */
    public Message() 
	{
        this("", null, null);
    }

    /**
     * * initializes the message as well as the source and destination of the
     * message
     *
     *            * @param message String
     * @param source UserAccount
     * @param destination UserAccount
     */
    public Message(String message, UserAccount source, Contact destination) {
        this.message = message;
        this.source = source;
        this.destination = destination;
        this.timestamp = new Timestamp(new Date().getTime());
    }

    /**
     * * sets a new message
     *
     *            * @param message String
     */
    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * * gets the current message
     *
     *            * @return message String
     */
    public final String getMessage() {
        return this.message;
    }

    /**
     * * gets the destination of the message
     *
     *            * @return destination UserAccount
     */
    public Contact getDestination() {
        return this.destination;
    }

    /**
     * * sets the destination of a message
     *
     *            * @param destination UserAccount
     */
    public void setDestination(Contact destination) {
        this.destination = destination;
    }

    /**
     * * gets the source of a message
     *
     *            * @return source UserAccount
     */
    public UserAccount getSource() {
        return this.source;
    }

    /**
     * * sets the source of a message
     *
     *            * @param source UserAccount
     */
    public void setSource(UserAccount source) {
        this.source = source;
    }

    @Override
    /**
     * * to string method for message class * return format [source ->
     * destination] message * return string
     */
    public String toString() {
        return "[" + this.timestamp.toString() + "]\n[" + this.source.getContactInfo().getFullName() + " -> " + this.destination.getFullName() + "] " + this.message;
    }
}
